/**
 * this class encapsulates calculations and data
 * for every triangle but not equilateral triangles.
 */
public class Triangle implements ITriangle {

	private double a, b, c;
	
	/**
	 * a triangle consists of three length-values.
	 * these lengths must be positiv.
	 */
	public Triangle(double a, double b, double c) {
		setA(a);
		setB(b);
		setC(c);
	}
	
	/**
	 * calculates the area of the triangle
	 * using the variables a, b and c.
	 */
	@Override
	public double area() {
		double s = (getA() + getB() + getC()) / 2;
		double area = Math.sqrt(Math.abs(s * (s-getA()) * (s-getB()) * (s-getC())));
		return area;
	}
	
	/**
	 * always returns 3 for triangles.
	 */
	@Override
	public final int edges() {
		return 3;
	}

	/**
	 * calculates the perimeter of an rectangle
	 * using the varialbes a, b and c.
	 *
	 */
	@Override
	public final double perimeter() {
		return (getA() + getB() + getC());
	}

	/**
	 * the lenght a must be positiv.
	 */
	public void setA(double a) {
		validateSideLength(a);
		this.a = a;
	}
	
	public double getA() {
		return a;
	}
	
	/**
	 * the lenght b must be positiv.
	 */
	public void setB(double b) {
		validateSideLength(b);
		this.b = b;
	}
	
	public double getB() {
		return b;
	}
	
	/**
	 * the lenght c must be positiv.
	 */
	public void setC(double c) {
		validateSideLength(c);
		this.c = c;
	}
	
	public double getC() {
		return c;
	}
	
	private void validateSideLength(double s) {
		if(s <= 0) {
			throw new IllegalArgumentException();
		}
	}
}
